﻿@namespace MudBlazor.UnitTests.TestComponents
<MudPopoverProvider></MudPopoverProvider>

<MudForm @ref="_form" IsValidChanged="@(HandleFormValidChanged)">
    <MudPaper>
        @($"Status: {_submitStatus ?? "Not yet submitted/validated"}")
    </MudPaper>
    
    <MudDateRangePicker @ref="@(_picker)" @bind-DateRange="@(_dateRange)" Label="Select Date Range" Required="true" RequiredError="This field is required!">
        <PickerActions>
            <MudButton Class="mr-auto align-self-start" OnClick="@(() => _picker.Clear())">Clear</MudButton>
            <MudButton OnClick="@(() => _picker.Close(false))">Cancel</MudButton>
            <MudButton Color="Color.Primary" OnClick="@(() => _picker.Close())">Ok</MudButton>
        </PickerActions>
    </MudDateRangePicker>

    <MudButton Class="mt-2" OnClick="@(() => _form.Validate())">Validate</MudButton>
</MudForm>

@code {
    public static string __description__ = $"The {nameof(MudDateRangePicker)} should shown an error when clicking validate without any data but this should disappear when a value has been set.";

    private MudForm _form;
    private MudDateRangePicker _picker;
    private string _submitStatus;
    private DateRange _dateRange; // = new(DateTime.Now, DateTime.Now.AddDays(2));

    private void HandleFormValidChanged(bool isValid)
    {
        _submitStatus = $"Form is {(isValid ? string.Empty : "in")}valid";
    }

}